package com.duowei.diandan.presenter;

import com.duowei.diandan.db.entry.Wmlsb;
import com.duowei.diandan.event.ToastEvent;
import com.duowei.diandan.fragment.OrderFragment;
import com.duowei.diandan.fragment.dialog.TasteDialogFragment;

import org.greenrobot.eventbus.EventBus;

public class OrderItemChildPresenter {

    private OrderFragment mFragment;

    public OrderItemChildPresenter(OrderFragment fragment) {
        mFragment = fragment;
    }

    // 点击口味
    public void onTasteClick(Wmlsb wmlsb) {
        if (canEditable(wmlsb)) {
            if (mFragment.getFragmentManager() != null) {
                TasteDialogFragment fragment = TasteDialogFragment.newInstance(wmlsb.getId());
                fragment.show(mFragment.getFragmentManager(), null);
                fragment.setOnClickListener(() -> {
                    mFragment.refreshDataSync();
                });
            }
        } else {
            EventBus.getDefault().post(new ToastEvent("不能修改", false));
        }
    }

    private boolean canEditable(Wmlsb wmlsb) {
        return wmlsb.getXh() == null && !"1".equals(wmlsb.getSfyxd());
    }
}
